package controller

import (
	"context"
	"github.com/gin-gonic/gin"
	"net/http"
	"zk1-project/bff/client"
	"zk1-project/bff/validate"
	pb "zk1-project/proto/exam"
)

func ExamRegister(c *gin.Context) {
	var examRegister validate.ExamReq
	if err := c.ShouldBindJSON(&examRegister); err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{
			"code": 500,
			"msg":  "服务器内部错误",
			"err":  err.Error(),
		})
		return
	}
	// 4. 调用接口
	res, err := client.Client().ExamRegister(context.Background(), &pb.ExamRegisterRequest{
		Name:                examRegister.Name,
		Sex:                 examRegister.Sex,
		IdNumber:            examRegister.IdNumber,
		RegistrationAddress: examRegister.RegistrationAddress,
		RegistrationDate:    examRegister.RegistrationDate,
		TestDate:            examRegister.TestDate,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": res.Code,
			"msg":  res.Msg,
		})
	}
	c.JSON(http.StatusOK, gin.H{
		"code": res.Code,
		"msg":  res.Msg,
		"data": res.Id,
	})

}
